package com.hangim.pce.enums;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.google.common.collect.Lists;

import java.util.List;

/**
 * 药品功用分类
 */
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum DrugUsageType {
    DIGESTIVE("DIGESTIVE", 1, "消化系统药"),
    ANTIBACTERIAL("ANTIBACTERIAL", 2, "抗菌药"),
    RESPIRATORY("RESPIRATORY", 3, "呼吸系统药"),
    CIRCULATION("CIRCULATION", 4, "血液循环系统药"),
    URINARY("URINARY", 5, "泌尿系统药"),
    ENDOCRINIUM("ENDOCRINIUM", 6, "内分泌系统药"),
    NERVOUS("NERVOUS", 7, "神经系统药"),
    ANAESTHETIC("ANAESTHETIC", 8, "麻醉药"),
    CARDIOVASCULAR("CARDIOVASCULAR", 9, "心脑血管药"),
    OTORHINOLARYNGOLOGY("OTORHINOLARYNGOLOGY", 10, "五官科药"),
    ANTIRHEUMATIC("ANTIRHEUMATIC", 11, "抗风湿类药"),
    DERMATOLOGY("DERMATOLOGY", 12, "皮肤科用药"),
    GYNAECOLOGY("GYNAECOLOGY", 13, "妇科用药"),
    ANTINEOPLASTIC("ANTINEOPLASTIC", 14, "抗肿瘤药"),
    ANTITOXICANT("ANTITOXICANT", 15, "清热解毒药"),
    DIABETES("DIABETES", 16, "糖尿病用药"),
    HORMONE("HORMONE", 17, "激素类药品"),
    NUTRITIOUS("NUTRITIOUS", 18, "滋补类药品"),
    ANTIALLERGIC("ANTIALLERGIC", 19, "受体激动、阻断药和抗过敏药"),
    VITAMIN("VITAMIN", 20, "维生素、矿物质药品"),
    OTHER("OTHER", 0, "其他");


    // 类型
    private final String code;
    // 描述
    private final String desc;
    // 编号
    private final Integer num;

    DrugUsageType(final String code, final Integer num, final String desc) {
        this.code = code;
        this.desc = desc;
        this.num = num;
    }

    /**
     * 把所有枚举定义转换成实体
     *
     * @return List<DrugUsageType>
     */
    public static List<DrugUsageType> getList() {
        List<DrugUsageType> list = Lists.newArrayList();

        DrugUsageType[] ts = DrugUsageType.values();
        for (DrugUsageType type : ts) {
            list.add(type);
        }
        return list;
    }

    public static DrugUsageType getDrugType(String code) {
        DrugUsageType[] ts = DrugUsageType.values();
        for (DrugUsageType t : ts) {
            if (t.getCode().equalsIgnoreCase(code)) {
                return t;
            }
        }
        return OTHER;
    }

    public static DrugUsageType getDrugUsageTypeDesc(String desc) {
        DrugUsageType[] ts = DrugUsageType.values();
        for (DrugUsageType t : ts) {
            if (t.getDesc().contains(desc)) {
                return t;
            }
        }
        return OTHER;
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public Integer getNum() {
        return num;
    }
}
